﻿/// <reference path="jquery.min.js" />
/// <reference path="rsseasy.app.js" />
/// <reference path="rsseasy.min.js" />

$(function () {
    var footer = $("#articleviewpage footer li");
    var articleid = 0;
    footer.click(function () {
        if (RssUser.Data.myid) {
            $(this).toggleClass("active");
            switch ($(this).index()) {
                case 0:
                    new Ajax("article/praise").keyvalue("myid", RssUser.Data.myid).keyvalue("articleid", articleid).get();
                    break;
                case 2:
                    new Ajax("article/collect").keyvalue("myid", RssUser.Data.myid).keyvalue("articleid", articleid).get();
                    break;
            }
        }
    });

    RssView.add("articlelist", function (out, data) {

        var html = "";
        $.each(data, function (key, val) {
            html += '<tr dataid="' + val["id"] + '"><td><div><img src="' + RssApp.UpHost + (val["ico"] + "").replace(".", "l.") + '" /></div></td><td><h2>' + val["title"] + '</h2><ul><li class="artcollect">' + val["collect"] + '</li><li class="artshare">' + val["share"] + '</li><li class="artpraise">' + val["praise"] + '</li></ul></td></tr>';
        });

        //获取文章详情
        out.html(html).find("tr").click(function (data) {
            footer.removeClass("active");
            RssView.AjaxNews($(this).attr("dataid"));

        });
    });
    var artview = RssPage.articleviewpage;
    RssView["AjaxNews"] = function (articleid) {
        new Ajax("article/view").keyvalue("id", articleid).keyvalue("myid", RssUser.Data.myid).getJson(function (data) {
            artview.article.html("<div><h2>" + data["title"] + "</h2><h3>发送人：&#12288;&#12288;上传时间：" + new Date(parseInt(data["shijian"]) * 1000).toString("yyyy-MM-dd HH:mm:ss") + "</h3>" + (data["matter"].replace("/upfile/", "").replace("src=\"", "src=\"" + RssApp.UpHost)).replace(".", "l.") + "</div>");

            if (parseInt(data["mypraise"])) {
                footer.eq(0).addClass("active");
            }
            if (parseInt(data["mycollect"])) {
                footer.eq(2).addClass("active");
            }
        });
        location.hash = "#articleviewpage";
    }
});
